<template>
    <div>
        <el-card shadow="hover">
            <div slot="header" class="flex jusc">
                <div class="head-title">
                    <span>登录日志</span>
                    <span class="table-choose" v-show="multipleSelection.length > 0">已选中{{ multipleSelection.length }}个</span>
                </div>
                <div class="flex">
                    <div>
                        <el-date-picker v-model="date" type="date" placeholder="选择日期"
                        format="yyyy 年 MM 月 dd 日"
                        value-format="yyyy-MM-dd">>
                        </el-date-picker>
                    </div>
                    <div class="head-btn">
                        <el-button type="primary" @click="search()">搜索</el-button>
                        <!-- <el-button type="danger">删除</el-button> -->
                    </div>
                </div>
            </div>
            <div>
                <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
                    v-loading="isLoading" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55">
                    </el-table-column>
                   <el-table-column prop="userId" label="用户ID"></el-table-column>
                    <el-table-column prop="username" label="用户名" width="200">
                    </el-table-column>
                   <el-table-column prop="ipAddress" label="IP地址"></el-table-column>
                   <el-table-column prop="loginTime" label="登录时间"></el-table-column>
                   
                    <!-- <el-table-column prop="address" label="操作" width="300">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="edit(scope.row)">编辑</el-button>
                        </template>
                    </el-table-column> -->
                </el-table>
            </div>
            <div class="pag">
                <el-pagination background layout="prev, pager, next" :current-page="currPage"
                    @current-change="handleCurrentChange" :page-size="pageSize" :total=total>
                </el-pagination>
            </div>
        </el-card>
    </div>
</template>

<script>
export default {
    name: "login-log",
    data() {
        return {
            date: null,
            tableData: [],
            pageSize: 10,
            isLoading: false,
            currPage: 1,
            total: 1,
            multipleSelection: [],
            searchContent: "", // 搜索内容
        }
    },
    mounted() {
        // this.getUserList()
        this.search()
    },
    methods: {
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        handleCurrentChange(val) {
            console.log(`当前页为：${val}`)
            this.currPage = val
            this.search()
        },
        async search() {
            this.isLoading = true
            let res = await this.$store.dispatch("getLogList", {
                date: this.date,
                pageSize: this.pageSize,
                // searchContent: this.searchContent,
                currPage: this.currPage,
            });
            this.isLoading = false
            if (res.success) {
                // console.log("data = " + res.data)
                this.tableData = res.data.list
                this.total = res.data.totalCount
                // console.log(this.tableData)
            }
            else this.$global.resError(res)
        }
    },
}
</script>

<style scoped>
.flex {
    display: flex;
    align-items: center;
}

.jusc {
    justify-content: space-between;
}

.head-btn {
    margin: 0 10px;
}

.login-log-list {
    background: rgb(248, 248, 248);
}

.pag {
    text-align: center;
    margin-top: 20px;
}

.head-title{
    font-size: 17px;
    font-weight: 550;
}

.table-choose{
    font-size: 13px;
    color: gray;
    margin-left: 10px;
}
</style>